//------------------------------------------------------------------------------
// <copyright company="Telligent Systems">
//     Copyright (c) Telligent Systems Corporation.  All rights reserved.
// </copyright> 
//------------------------------------------------------------------------------

using System;
using System.Web;

namespace CommunityServer.Components 
{
	/// <summary>
	/// Summary description for ForumUserOptions.
	/// </summary>
	public class ForumUserOptions 
	{
		public SortThreadsBy SortBy = SortThreadsBy.LastPost;
		public SortOrder SortOrder = SortOrder.Descending;
		public ThreadUsersFilter UserFilter = ThreadUsersFilter.All;
		public ThreadDateFilterMode DateFilter = ThreadDateFilterMode.All;
		public bool HideReadPosts = false;
		public bool HasSettings = false;

		public ForumUserOptions(string settings) 
		{

			if ((settings == null) || (settings == string.Empty))
				return;

			HasSettings = true;

			try 
			{
				// Serialized format is: [SortBy]:[SortOrder]:[DateFilter]:[HideReadPosts]:[UserFilter]
				string[] s = settings.Split(':');

				SortBy = (SortThreadsBy) int.Parse(s[0]);
				SortOrder = (SortOrder) int.Parse(s[1]);
				DateFilter = (ThreadDateFilterMode) int.Parse(s[2]);

				if (s[3] == "T")
					HideReadPosts = true;
				else
					HideReadPosts = false;

				UserFilter = (ThreadUsersFilter) int.Parse(s[4]);
			} 
			catch {}

		}

	}
}
